<template>
  <div id="data-box">
    <div class="data-div1">
      <el-table
          :data="tableData"
          style="width: 100%"
          :row-class-name="tableRowClassName">
        <el-table-column
            show-overflow-tooltip
            prop="city1"
            label="城市">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="date"
            label="日期">
        </el-table-column>
        <el-table-column
            prop="maxT"
            label="最高气温">
        </el-table-column>
        <el-table-column
            prop="minT"
            label="最低气温">
        </el-table-column>
        <el-table-column
            prop="weather"
            show-overflow-tooltip
            label="天气">
        </el-table-column>
        <el-table-column
            prop="wind"
            show-overflow-tooltip
            label="风向">
        </el-table-column>
      </el-table>
    </div>
    <div class="data-div2" v-show="tableData.length > 0">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage1"
          :page-sizes="[16, 32, 64, 128]"
          :page-size="100"
          layout="total, sizes, prev, pager, next, jumper"
          :total=pageCount>
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: 'DataManagement',
  data() {
    return {
      pageSize: 16,
      pageCount: 0,
      currentPage1: 1,
      tableData: []
    }
  },
  mounted() {
    this.getPageCount();
    this.getDataAll(0, this.pageSize);
  },
  methods: {
    tableRowClassName({row, rowIndex}) {
      if (rowIndex === 1) {
        return 'warning-row' + row;
      } else if (rowIndex === 3) {
        return 'success-row';
      }
      return '';
    },
    //  分页
    handleSizeChange(val) {
      this.pageSize = val;   // 没有分页数
    },
    handleCurrentChange(val) {
      this.tableData = [];
      let start = (val - 1) * this.pageSize;
      this.getDataAll(start, this.pageSize)

    },
    getPageCount() {
      this.$axios.get('/api/vis/data9', {}).then(res => {
        if (res.data.code === 20041) {
          this.pageCount = res.data.data;
        }
      }).catch(error => {
        this.open4(error);
      })
    },
    getDataAll(start, end) {
      this.$axios.post('/api/vis/data10', {
        "start": start,
        "end": end
      }).then(res => {
        if (res.data.code === 20041) {
          this.tableData = [];
          for (let i = 0; i < res.data.data.length; i++) {
            this.tableData.push(
                {
                  city1: res.data.data[i].column0,
                  date: res.data.data[i].column1,
                  maxT: res.data.data[i].column2,
                  minT: res.data.data[i].column3,
                  weather: res.data.data[i].column4,
                  wind: res.data.data[i].column5
                }
            )
          }
        }
      }).catch(error => {
        this.open4(error);
      })
    }
  }
}
</script>

<style scoped>

#data-box {
  height: 100%;
  width: 100%;
  .el-table .warning-row {
    background: oldlace;
  }

  .el-table .success-row {
    background: #f0f9eb;
  }
  overflow-x: hidden;
  overflow-y: auto;
}
#data-box .data-div1 {
  width: 100%;
  margin: auto;
}
#data-box .data-div2 {
  width: 40%;
  margin: auto;
}

</style>